 const fs = require('fs-extra');
 
//  判断用户是否是第一个使用

let time = new Date();
let y = time.getFullYear();
let m = time.getMonth()+1;
let d = time.getDate();
// 数据库初始化
const readfilejson = async (path)=>{ 
     let str =  await fs.readJson(path);
    // frist 作为初始化的唯一标识，因为用户有可能存在清空的情况
     if(Boolean(str['First'])){
        let day = `${y}-${m}-${d}`;
        let objs = {[day]:'欢迎使用'}; 
        await fs.writeJson(path,objs);
        process.send?.(true);
     }else{ 
        process.send?.(false);
     } 
     process.exit(); 
}


//子进程
const begin = process.argv[2]
// console.log(process.send) 
if(process.send){
    process.on('message', (msg) => {
        // console.log('from parent', msg); 
    })
    //监听master传来的message
     readfilejson('db.json'); 
    //向master发送信息 
}
